package com.ruoyi.project.sms.controller;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.sms.domain.SmsAdvertise;
import com.ruoyi.db.sms.domain.query.SmsAdvertiseQueryVo;
import com.ruoyi.project.sms.service.SmsAdvertiseService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 首页广告Controller
 *
 * @author yfy
 * @date 2020-04-21
 */
@Api(tags="sms管理：首页广告管理")
@RestController
@RequestMapping("/sms/advertise")
public class SmsAdvertiseController extends BaseController
{
    @Autowired
    private SmsAdvertiseService smsAdvertiseService;

    /**
     * 状态修改
     */
    @ApiOperation("修改首页广告启动状态")
    @PreAuthorize("@ss.hasPermi('pms:brand:edit')")
    @Log(title = "启动状态", businessType = BusinessType.UPDATE)
    @PutMapping("/changeIsEnabledStatus")
    public AjaxResult changeIsEnabledStatus(@RequestBody SmsAdvertise smsAdvertise)
    {
        smsAdvertise.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(smsAdvertiseService.changeIsEnabledStatus(smsAdvertise));
    }

    @ApiOperation("查询首页广告列表")
    @PreAuthorize("@ss.hasPermi('sms:advertise:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsAdvertiseQueryVo smsAdvertiseQueryVo)
    {
        startPage();
        List<SmsAdvertise> list = smsAdvertiseService.selectSmsAdvertiseList(smsAdvertiseQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出首页广告列表")
    @Log(title = "首页广告", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('sms:advertise:export')")
    @GetMapping("/export")
    public AjaxResult export(SmsAdvertiseQueryVo smsAdvertiseQueryVo)
    {
        List<SmsAdvertise> list = smsAdvertiseService.selectSmsAdvertiseList(smsAdvertiseQueryVo);
        ExcelUtil<SmsAdvertise> util = new ExcelUtil<SmsAdvertise>(SmsAdvertise.class);
        return util.exportExcel(list, "advertise");
    }

    @ApiOperation("获取首页广告详细信息")
    @Log(title = "首页广告", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('sms:advertise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsAdvertiseService.selectSmsAdvertiseById(id));
    }

    @ApiOperation("新增首页广告")
    @Log(title = "首页广告", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms:advertise:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SmsAdvertise smsAdvertise)
    {
        return toAjax(smsAdvertiseService.insertSmsAdvertise(smsAdvertise));
    }

    @ApiOperation("修改首页广告")
    @Log(title = "首页广告", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms:advertise:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SmsAdvertise smsAdvertise)
    {
        return toAjax(smsAdvertiseService.updateSmsAdvertise(smsAdvertise));
    }

    @ApiOperation("删除首页广告")
    @Log(title = "首页广告", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms:advertise:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsAdvertiseService.deleteSmsAdvertiseByIds(ids));
    }
}
